package cn.wx.user.controller;

import cn.wx.basic.exception.BusinessException;
import cn.wx.basic.util.JsonResult;
import cn.wx.user.dto.WxDto;
import cn.wx.user.service.ILogininfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/login")
public class LogininfoController {

    @Autowired
    private ILogininfoService iLogininfoService;


    @PostMapping("/account")
    public JsonResult account(@RequestBody Map<String,String> map){

        try {
           Map<String,Object> map1 =  iLogininfoService.account(map);
           return JsonResult.me().setResultObj(map1);
        } catch ( BusinessException e) {
            e.printStackTrace();
            return JsonResult.me().setMsg(e.getMessage());
        }catch (Exception e){
            return  JsonResult.me().setMsg("网络繁忙");
        }

    }

/*
* 微信登录
*
* */
    @GetMapping("/weChat/{code}")
    public JsonResult weChat(@PathVariable(value = "code") String code){

        try {
            return iLogininfoService.weChat(code);
        } catch ( BusinessException e) {
            e.printStackTrace();
            return JsonResult.me().setMsg(e.getMessage());
        }catch (Exception e){
            return  JsonResult.me().setMsg("网络繁忙");
        }
    }

    /*
        微信绑定
         */
    @PostMapping("/wechat/binder")
    public JsonResult binder(@RequestBody WxDto dto) {

        try {
            return iLogininfoService.binder(dto);
        } catch (BusinessException e) {
            e.printStackTrace();
            return JsonResult.me().setMsg(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return JsonResult.me().setMsg("网络繁忙");
        }


    }
}
